(function($){
    
    $.fn.desktopNotifyAddPermission = function(options) {
        this.click(function(e) {
            if (webkitNotifications.checkPermission()) {
                webkitNotifications.requestPermission();
            }
        });
        return this;
    };
    
    $.fn.desktopNotify = function(options) {
    
        var defaults = {
            file:    "../pages/notification.html",
            timeout: 10000,
            ondisplay: function(e){},
            onclose: function(e){}
        };

        var setting = $.extend(defaults, options);
        
        if (!webkitNotifications.checkPermission()) {
            var popup = webkitNotifications.createHTMLNotification(setting.file);
            popup.ondisplay = setting.ondisplay;
            popup.onclose = setting.onclose;
            popup.show();
            setTimeout(function(){popup.cancel();}, setting.timeout);
        }

        return this;
    };

})(jQuery);
